/***********************************************************************
 FrameBuffer.h - Declare class to manage an in-memory frame buffer for
 	creating the slate bitmap.

 Copyright (c) 2006 by Pixel Corps.  This program may be used under
 the terms of the X11 license, a copy of which should have accompanied
 this program, in the LICENSE file.
***********************************************************************/

#if !defined(SLATEGEN_FRAMEBUFFER_H)
#define SLATEGEN_FRAMEBUFFER_H

#include <SDL_ttf.h>
#include <SDL_types.h>

#include <string>
#include <vector>

struct SDL_PixelFormat;
struct SDL_Surface;

class FrameBuffer
{
public:
	//// Public types
	// Image file formats we can write
	enum ImageType {
		kImage_PNG,
		kImage_TIFF,
	};
	
	//// Public interface
	FrameBuffer();

	// Write a right-justified label followed by a left-justified block
	// of text on the drawing surface.
	bool WriteText(const char* pcLabel, const char* pcText);

	// Write the SDL drawing surface data to an image file of a given
	// format.  pcFileName is expected to point to a file name without
	// the image format extension.  We append the right one internally.
	bool WriteImage(const char* pcFileName, ImageType eType);

protected:
	//// Internal class interface
	bool CompositePNG(const char* pcFileName, int x, int y);
	void Error(const char* prefix);
	SDL_PixelFormat* PixelFormat();
	void Lock();
	Uint32 RGB(int r, int g, int b);
	SDL_Surface* Surface() { return pSurface_; }
	void Unlock();
	void Update();
	const char* WordEnd(const char* pc);
	void WrapText(const char* pcText, std::vector<std::string>* pLines);

private:
	//// Internal data
	SDL_Surface* pSurface_;
	TTF_Font* pRegularFont_, *pBoldFont_;
	int nLines_;
	int nGroups_;
};

#endif // !defined(SLATEGEN_FRAMEBUFFER_H)

